package io.zhaocy.acmspringboot.handler;
/**
 * @author genezhao
 * @date 2018/1/4
 * @since
 */

import com.baomidou.mybatisplus.mapper.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

/**
 * <p>Description: 自定义填充公共字段create_time update_time</p>
 *
 * @author genezhao
 * @since
 */
public class DateTimeMetaObjectHandler extends MetaObjectHandler{

    @Override
    public void insertFill(MetaObject metaObject) {
        Object createTimeField = getFieldValByName("createTime", metaObject);
        Object updateTimeField = getFieldValByName("updateTime", metaObject);
        if (null == createTimeField) {
            setFieldValByName("createTime", System.currentTimeMillis(), metaObject);
        }
        if (null == updateTimeField) {
            setFieldValByName("updateTime", System.currentTimeMillis(), metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        setFieldValByName("updateTime", System.currentTimeMillis(), metaObject);
    }
}
